﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ClassLibrary.DAO;

public partial class MasterPage : System.Web.UI.MasterPage
{
    TblDSLKDAO dslkDAO = new TblDSLKDAO(Global.CONNECTION_STRING);
    TblSupplierDAO supplierDAO = new TblSupplierDAO(Global.CONNECTION_STRING);
    TblParentMenuDAO menuParentDAO = new TblParentMenuDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadSuppliers();
            LoadMenuParent();
            LoadDSLK();
        }
    }
    private void LoadDSLK()
    {
        try
        {
            lvdanhsachlienket.DataSource = dslkDAO.GetDSLK();
            lvdanhsachlienket.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE);
        }
    }
    private void LoadMenuParent()
    {
        try
        {
            lvsanpham.DataSource = menuParentDAO.GetMenuParent();
            lvsanpham.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect("~/Error.aspx", true);
        }

    }
    private void LoadSuppliers()
    {
        try
        {
            lstCategories.DataSource = supplierDAO.GetAll();
            lstCategories.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect("~/Error.aspx", true);
        }
    }
    protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    {
         Response.Redirect("~/KetQuaTimKiem.aspx?text=" + HttpUtility.UrlEncode(txtSearch.Text.Trim())+"&id1=" + Global.ConvertToInt (drchon.SelectedValue.ToString()));
    }
}
